package com.itheima.controller;



import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;


    @GetMapping
    private Result findStudent ( StudentQueryParam studentQueryParam ) {

        PageResult pageResult = studentService.findStudent(studentQueryParam);
        return Result.success(pageResult);
    }

    @PostMapping
    private Result saveStudent ( @RequestBody Student student ) {
        studentService.saveStudent(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    private Result getStudentById ( @PathVariable("id") Integer id ) {
        Student student = studentService.getStudentById(id);
        return Result.success(student);
    }

    @PutMapping
    private Result updateStudent ( @RequestBody Student student ) {
        studentService.updateStudent(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result deleteStudent ( @PathVariable List<Integer> ids ) {
        studentService.deleteStudent(ids);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result violation ( @PathVariable("id") Integer id, @PathVariable("score") Integer score ) {
        studentService.violation(id, score);
        return Result.success();

    }

}

